function g(o){
    return document.getElementById(o);
}

function HoverLi(n){
    for(var i=1;i<=2;i++){
        g('tbec_'+i).className='BTabOtherTab';
    }
    g('tbec_'+n).className='BTabCurrentTab';
    document.goodsListFrom.action = getHost()+"stock/stockAlertList/index/PageModel/" + n;
    document.goodsListFrom.submit();
}

function goods_dataSearch() {
    clearErrorMsg();
    goods_search(1, "", "", "1");
    setSearchOrder("orderHead");
}
function goods_search(intCurPage, strOrderColumn, strOrder, strFlag, pageSize) {
    if(strFlag == "1") {
        ajaxRequest(getHost()+"stock/stockAlertList/search", {
            "curPage"       : intCurPage,
            "pageSize"      : pageSize,
            "GoodsCode"     : getValue("txtGoodsCode"),
            "GoodsName"     : getValue("txtGoodsName"),
            "StockNumFg"    : getValue("hidNumFg"),
            "StockNumFrom"  : getValue("txtNumFrom"),
            "StockNumTo"    : getValue("txtNumTo"),
            "Flag"          : strFlag
        }, goods_goodsListView);
    } else {
        ajaxRequest(getHost()+"stock/stockAlertList/search", {
            "curPage"       : intCurPage,
            "pageSize"      : pageSize,
            "orderColumn"   : strOrderColumn,
            "order"         : strOrder,
            "Flag"          : strFlag
        }, goods_goodsListView);
    }
}
function goods_setTextType(strfg){
    setValue("hidNumFg",strfg);
    if(strfg == "3") {
        setDisabled("txtNumFrom",false);
        setDisabled("txtNumTo",false);
    } else {
        setDisabled("txtNumFrom",true);
        setDisabled("txtNumTo",true);
    }
}
function goods_reset() {
    clearErrorMsg();
    setValue("txtGoodsCode","");
    setValue("txtGoodsName","");
    document.getElementById("rdoNumAll").checked = true;
    setValue("txtNumFrom","");
    setValue("txtNumTo","");
}
function goods_goodsListView(data) {
    if (data.count <= 0){
        setTableData("tblDataTable", data.searchData, null, null);
        pageCreat(1,data.count,"pageHead");
        pageCreat(1,data.count,"pageFoot");
        return;
    }
    if (getValue("hidPageModel") == "1") {
        arrCols = new Array(
                "setCheckBox(GOODS_NO, SUGGEST, Checkfg)",
                "setRowNo(_rowno)",
                "setGoodsCode(GOODS_CODE,GOODS_NO)",
                "setGoodsName(GOODS_NAME,GOODS_NO)",
                "setVariation(VARIATION,SIMVARIATION)",
                "STOCK_NUM",
                "SUGGEST",
                "setSup(NAME_GROUP,SUPPLIERNUM)");
        arrColStyle = new Array(
                "text-align:center",
                "text-align:right",
                "",
                "",
                "",
                "text-align:right",
                "text-align:right",
                "text-align:right"
            );
    } else {
        arrCols = new Array(
                "setRowNo(_rowno,GOODS_NO,DATA_VERSION)",
                "setGoodsCode(GOODS_CODE,GOODS_NO)",
                "setGoodsName(GOODS_NAME,GOODS_NO)",
                "setVariation(VARIATION,SIMVARIATION)",
                "setSel(SUGGEST_TP)",
                "setMin(STOCK_MIN)",
                "setMax(STOCK_MAX)");
        arrColStyle = new Array(
                "text-align:right",
                "",
                "",
                "",
                "text-align:right",
                "text-align:right",
                "text-align:right"
            );
    }
    arrRows =new Array(
            "",
            "BListTableGray");
    pageCreat(data.curPage,data.count,"pageHead");
    pageCreat(data.curPage,data.count,"pageFoot");
    setTableData("tblDataTable", data.searchData, arrCols, arrColStyle,false,arrRows);

    
}

function setRowNo(_rowno, strNo, strdv) {
    var intCurPage  = getCurPage();
    var intPageSize = getPageSize();
    var strA = "";
    if (strNo != undefined && strdv != undefined) {
        strA="<input type=\"hidden\" id=\"hidDataVersion\" name=\"hidDataVersion\" value=\""+strNo+","+strdv +"\"/>";
    }
    return (intCurPage - 1) * intPageSize + _rowno + 1+strA;
}
function setCheckBox(strNo,intNum, strCheckfg) {
    if (strCheckfg == 1) {
        return "<input type=\"checkbox\" id=\"chkGoods\" name=\"chkGoods\" value=\""+strNo+"," + intNum +"\"/>";
    } else if (strCheckfg == 2) {
        return "<input type=\"checkbox\" id=\"chkGoods\" name=\"chkGoods\" disabled value=\""+strNo+"," + intNum +"\"/>";
    } else {
        return "";
    }
}
function setGoodsCode(goodsCode,goodsNo) {
    return "<a  href=\"" + getHost()+"goods/goodsDetails/index/goodsNo/"+ goodsNo + "\">" + goodsCode + "</a>";
}
function setGoodsName(goodsName,goodsNo) {
    return "<a  href=\"" + getHost()+"goods/goodsDetails/index/goodsNo/"+ goodsNo + "\">" + goodsName + "</a>";
}
function setVariation(VARIATION,SIMVARIATION) {
    return "<span title = '" + VARIATION + "'>" + SIMVARIATION +"</span>";
}
function setSup(NAME_GROUP,SIMNAME_GROUP) {
    return "<span title = '" + NAME_GROUP + "'>" + SIMNAME_GROUP +"</span>";
}

function setSel(strTp) {
    strA = "<select name=\"selSuggest\" id=\"selSuggest\"><option value=\"1\" "
    if (strTp=="1") {
        strA = strA+ "selected";
    }
    strA = strA+ ">库存限制</option><option value=\"2\" "
    if (strTp=="1") {
        strA = strA+ "selected";
    }
    strA = strA+ ">销量算法</option></select>";
    return strA;
}
function setMin(intMin) {
    return "<input type=\"text\" name=\"txtStockMin\" id=\"txtStockMin\" value=\"" +intMin+"\" style=\"text-align:right\"/>";
}
function setMax(intMax) {
    return "<input type=\"text\" name=\"txtStockMax\" id=\"txtStockMax\" value=\"" +intMax+"\" style=\"text-align:right\"/>";
}
function gotoPage(strPageContainerId, strOrderContainerId) {
    goods_search(getCurPage(strPageContainerId), getOrderColumn(strOrderContainerId), getOrder(strOrderContainerId), "2", getPageSize(strPageContainerId));
}

function firstPage(strPageContainerId, strOrderContainerId) {
    goods_search(getCurPage(strPageContainerId), getOrderColumn(strOrderContainerId), getOrder(strOrderContainerId), "2", getPageSize(strPageContainerId));
}

function prePage(strPageContainerId, strOrderContainerId) {
    goods_search(getCurPage(strPageContainerId), getOrderColumn(strOrderContainerId), getOrder(strOrderContainerId), "2", getPageSize(strPageContainerId));
}

function nextPage(strPageContainerId, strOrderContainerId) {
    goods_search(getCurPage(strPageContainerId), getOrderColumn(strOrderContainerId), getOrder(strOrderContainerId), "2", getPageSize(strPageContainerId));
}

function lastPage(strPageContainerId, strOrderContainerId) {
    goods_search(getCurPage(strPageContainerId), getOrderColumn(strOrderContainerId), getOrder(strOrderContainerId), "2", getPageSize(strPageContainerId));
}

function orderSearch(strPageContainerId, strOrderContainerId) {
    goods_search(getCurPage(strPageContainerId), getOrderColumn(strOrderContainerId), getOrder(strOrderContainerId), "2", getPageSize(strPageContainerId));
}
function sizeChangeSearch(strPageContainerId, strOrderContainerId) {
    goods_search(getCurPage(strPageContainerId), getOrderColumn(strOrderContainerId), getOrder(strOrderContainerId), "2", getPageSize(strPageContainerId));
}

function save(){
    objA = document.getElementsByName("hidDataVersion");
    objB = document.getElementsByName("selSuggest");
    objC = document.getElementsByName("txtStockMin");
    objD = document.getElementsByName("txtStockMax");
    arrId =new Array();
    arrVer =new Array();
    arrSuggest =new Array();
    arrMin =new Array();
    arrMax =new Array();
    for(var i=0; i<objA.length; i++) {
        arrTemp = objA[i].value.split(",")
        arrId[i] = arrTemp[0];
        arrVer[i] = arrTemp[1];
        arrSuggest[i] = objB[i].value;
        arrMin[i] = objC[i].value;
        arrMax[i] = objD[i].value;
    }
    ajaxRequest(getHost()+"stock/stockAlertList/save", {
        "Id" : arrayToJson(arrId),
        "Ver" : arrayToJson(arrVer),
        "Suggest" : arrayToJson(arrSuggest),
        "Min" : arrayToJson(arrMin),
        "Max" : arrayToJson(arrMax)
    }, saveCallBack);
}
function saveCallBack(data){
    if(data.count != 0) {
        window.location.href=getHost()+"stock/stockAlertList/index/PageModel/2/ReturnFg/2";
    } else {
        Jconfirm(data.ReturnFg, null, null);
        setDisabled("btnSave", true);
    }
}
function order(){
    strGoods = getCheckboxValue("chkGoods");
    ajaxRequest(getHost()+"stock/stockAlertList/order", {
        "Goods" : strGoods
    }, orderCallBack);
}
function orderCallBack(data){
    document.goodsListFrom.action = getHost()+"order/orderEdit/index/";
    document.goodsListFrom.submit();
}